#include "ringbuffer.hpp"
#include <iostream>

int main()
{
	int32_t ret = 0;
	uint8_t buff[93] = "test\0";
	uint8_t out[93] = "";
	RingBuffer *rb = new RingBuffer(512);
	uint8_t cnt = 0;
	rb->init();
	uint8_t c = 0;

	printf("test 1\n");
	while (1) {
		for (int32_t i = 0; i < sizeof(buff); i++) {
			buff[i] = c;
			c++;
		}
		ret = rb->writeToRing(buff, 93);
		printf("ret = %d\n", ret);
		if (ret < 0)
			break;
	}
	while (1) {
		ret = rb->readFromRing(out, 16);
		printf("ret = %d\n", ret);
		if (ret <= 0)
			break;
		for (int i = 0; i < 16; i++)
			printf(" %02x", out[i]);
		printf("\n");
	}
	c = 0;
	for (int32_t i = 0; i < sizeof(buff); i++) {
		buff[i] = c;
		c++;
	}

	printf("test 2\n");
	while (1) {
		ret = rb->writeToRing(buff, 93);
		printf("write ret = %d\n", ret);
		if (ret > 0) {
			for (int32_t i = 0; i < sizeof(buff); i++) {
				buff[i] = c;
				c++;
			}
		}
		ret = rb->readFromRing(out, 16);
		printf("read ret = %d\n", ret);
		for (int i = 0; i < 16; i++)
			printf("%02x", out[i]);
		printf("\n");
	}
	delete rb;
	return 0;
}